function isEmail(str) {
   return (str.search(/^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/) != -1)
}

function fromFlash(){
		window.open('minisites/comp/minisite.php','mini','width=840,height=605');
}

function printswf(str){
	document.write(str);	
}



var credit_card_str = "0123456789";
var amount_str = "0123456789.";
var letters_str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

function only_given_chars(id,str_given){
var sText=document.getElementById(id).value;
var new_sText='';
 if(!ChkStrBy(sText,str_given)){
 	for(var i=0;i<=sText.length;i++){
	if(i<(sText.length) && ChkStrBy(sText.charAt(i),str_given))
		new_sText+=sText.charAt(i);
	}
	document.getElementById(id).value=new_sText;
 }
}

function ChkStrBy(sText, sValidChars){
 var ret = true;
 if (sText.length==0) return (false);
 for (i = 0 ; i < (sText.length) && (ret==true) ; i++){
 if (sValidChars.indexOf(sText.charAt(i)) == -1){
 ret = false;
 }
 }
 return (ret);
}

function do_login(){
	window.open('https://login.forexwebtrader.com/site/','login','width=250, height=150');
	}
    
    function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}



function  pop_sub(parent_id,child_id,opacity){
 var obj=document.getElementById(parent_id);
 if(obj.dir=='rtl'){
    var ext_left=-70;
 }else var ext_left=0;
 
 var pos=findPos(obj);
 var left=pos[0];
 var top=pos[1]; 
 //alert(left+','+top);
 var child_menu=document.getElementById(child_id);
 
 
 child_menu.style.top=(top+15)+'px';
 child_menu.style.left=(left+1+ext_left)+'px';
 make_vis(child_id,opacity) 
}


function make_vis(id,opacity){ 
	var obj=document.getElementById(id);
if(opacity==true){ 
	changeOpac_menu(0,id);
	obj.style.visibility='visible';
	opacity_menu(id, 0, 90, 400);
 }
     else
     obj.style.visibility='visible';
 }

function un_vis(id,opacity){
    var obj=document.getElementById(id);
    obj.style.visibility='hidden'; 
}









function opacity_menu(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac_menu(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac_menu(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac_menu(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}  

function valid_input(input_type, input_str)
{
    if(input_type == 'text')
    {        
        if(!input_str.match(/^([ a-zA-Z\-\.\,]*)$/)){
            return false;
        }
    }
    else if(input_type == 'alphanumeric')
    {
        if(!input_str.match(/^([ a-zA-Z0-9\-\.\,\/\']*)$/)){
            return false;
        }
    }
    else if(input_type == 'number')
    {
        if(!input_str.match(/^([0-9]*)$/)){
            return false;
        }
    }
    else if(input_type == 'special_char')
    {
        if(input_str.match(/.*([&]+).*/)){
            return false;
        }
    }
    return true;
}
function legal_name(first_name, last_name)
{
    var full_name = first_name + last_name;
    if(full_name.length < 4){
        return false;
    }
    return true;
}
function check_expiry_date(exp_m, exp_y)
{    
    if((parseInt(exp_y) > parseInt(document.getElementById('current_year').value)) || 
        ((parseInt(exp_y) == parseInt(document.getElementById('current_year').value)) && 
        (exp_m >= document.getElementById('current_month').value)))
    {                    
        return true;
    }
    else{                
        return false;
    }
}

function validate_cc(cc_type, cc_number)
{
    var masterCard = 1;
    var visa  = 2;
    var diners = 3;
    var amExpress = 4;
    var jcb = 5;
    var discover = 6;

    var validFormat = false;
    var passChecked = false;        
    

    if(cc_type == masterCard)
    {
        if(cc_number.match(/^5[1-5][0-9]{14}$/)){
            validFormat = true;
        }
    }
    else if(cc_type == visa)
    {
        if(cc_number.match(/^4[0-9]{12}([0-9]{3})?$/)){
            validFormat = true;
        }
    }
    else if(cc_type == diners)
    {
        if(cc_number.match(/^3(0[0-5]|[68][0-9])[0-9]{11}$/)){
            validFormat = true;
        }          
    }
    else if(cc_type == amExpress)
    {
        if(cc_number.match(/^3[47][0-9]{13}$/)){
            validFormat = true;
        }          
    }
    else if(cc_type == jcb)
    {
        if(cc_number.match(/^(3[0-9]{4}|2131|1800)[0-9]{11}$/)){
            validFormat = true;
        }          
    }
    else if(cc_type == discover)
    {
        if(cc_number.match(/^6011[0-9]{12}$/)){
            validFormat = true;
        }          
    }    
    if(validFormat)
    {
        var passCheck = false;
        var cardNumber = rev_str(cc_number);
        
        var numSum = 0;         
        for(var i = 0; i < cardNumber.length; i++) 
        {            
            currentNum = cardNumber.substr(i, 1); 

            // Double every second digit 
            if(i % 2 == 1) 
            { 
              currentNum *= 2; 
            } 

            // Add digits of 2-digit numbers together 
            if(currentNum > 9) 
            { 
              firstNum = currentNum % 10; 
              secondNum = (currentNum - firstNum) / 10; 
              currentNum = firstNum + secondNum; 
            } 

            numSum = numSum + parseInt(currentNum);
            
        }
        
        reminder = numSum % 10;
        if(reminder == 0){
            passCheck = true;        
        }
        
          
        if(passCheck){
         return true; 
         }
         else{
          return false; 
          }
        
    }
    return false;
    
}

function rev_str(str)
{
   return str.split("").reverse().join("");
}

function open_login()
{                      
    window.open('http://www.forexwebtrader.com/loginForex','login' + Math.floor(Math.random()*10001),"width=744,height=425,resizable=yes,scrollbars=yes");
    return; 
   /* login_web2();  */
    return;
}

function login_web()
{
    window.open('https://login.forexwebtrader.com/site/','login_web' + Math.floor(Math.random()*10001),'width=170, height=120');
    window.close();
    return;
}

function login_web2()
{    
    if(lang == 'de')
    {
        window.open('https://login.finexo.com/?lang=DE','login_web2' + Math.floor(Math.random()*10001),"width=" + screen.availWidth +",height=" + screen.availHeight + ",resizable=yes,scrollbars=yes");
    }else if(lang == 'tr')
    {
        window.open('https://login.finexo.com/?lang=TR','login_web2' + Math.floor(Math.random()*10001),"width=" + screen.availWidth +",height=" + screen.availHeight + ",resizable=yes,scrollbars=yes");
    }else if(lang == 'fr')
    {
        window.open('https://login.finexo.com/?lang=FR','login_web2' + Math.floor(Math.random()*10001),"width=" + screen.availWidth +",height=" + screen.availHeight + ",resizable=yes,scrollbars=yes");
    }else if(lang == 'ru')
    {
        window.open('https://login.finexo.com/?lang=RU','login_web2' + Math.floor(Math.random()*10001),"width=" + screen.availWidth +",height=" + screen.availHeight + ",resizable=yes,scrollbars=yes");
    }else if(lang == 'es')
    {
        window.open('https://login.finexo.com/?lang=ES','login_web2' + Math.floor(Math.random()*10001),"width=" + screen.availWidth +",height=" + screen.availHeight + ",resizable=yes,scrollbars=yes");
    }else if(lang == 'hu')
    {
        window.open('https://login.finexo.com/?lang=HU','login_web2' + Math.floor(Math.random()*10001),"width=" + screen.availWidth +",height=" + screen.availHeight + ",resizable=yes,scrollbars=yes");
    }else if(lang == 'ar')
    {
        window.open('https://login.finexo.com/?lang=AR','login_web2' + Math.floor(Math.random()*10001),"width=" + screen.availWidth +",height=" + screen.availHeight + ",resizable=yes,scrollbars=yes");
    }else if(lang == 'br')
    {
        window.open('https://login.finexo.com/?lang=PT','login_web2' + Math.floor(Math.random()*10001),"width=" + screen.availWidth +",height=" + screen.availHeight + ",resizable=yes,scrollbars=yes");
    }else if(lang == 'cn')
    {
        window.open('https://login.finexo.com/?lang=ZH-CN','login_web2' + Math.floor(Math.random()*10001),"width=" + screen.availWidth +",height=" + screen.availHeight + ",resizable=yes,scrollbars=yes");
    }else
    {
        window.open('https://login.finexo.com/','login_web2' + Math.floor(Math.random()*10001),"width=" + screen.availWidth +",height=" + screen.availHeight + ",resizable=yes,scrollbars=yes");
    }
    return;
}


function getCookie(c_name)
{
    if (document.cookie.length>0)
      {
      c_start=document.cookie.indexOf(c_name + "=");
      if (c_start!=-1)
        { 
        c_start=c_start + c_name.length+1; 
        c_end=document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end=document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
        } 
      }
      return "";
}