 var reEmail=/^.+\@.+\..+$/

function CPA(page){
  document.forms.mainform.page.value=page;
  document.forms.mainform.submit();
}

function CP(page){
  document.location='index.php?page='+page;
  //document.forms.mainform.page.value=page;
  //document.forms.mainform.submit();
}

//*************************************************************************************************
function CPNW(page){
  windowprops = "screenX=0,screenY=0,top=1,left=1,status=no,directories=no,location=no,toolbar=no,resizable=no,menubar=no,scrollbars=yes,width="+(screen.width-10)+",height="+(screen.height-60);
  window.open('index.php?page='+page,'UWT', windowprops);
}

//*************************************************************************************************
function CPNURL(name,url){
  windowprops = "screenX=0,screenY=0,top=1,left=1,status=yes,directories=yes,location=yes,toolbar=yes,resizable=yes,menubar=yes,scrollbars=yes,width="+(screen.width-10)+",height="+(screen.height-60);
  window.open(url,name,windowprops);
}

function CA(action,actionid,conf){
  if (conf!=1 || confirm('Are your sure?')){
    if (action!='') document.forms.mainform.action.value=action;
    if (actionid!='') document.forms.mainform.actionid.value=actionid;
    document.forms.mainform.submit();
  }
}


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//*************************************************************************************************
function show_hide_part(part_name){
  if (document.all){
    if(document.all[part_name].style.display == 'none'){
      document.all[part_name].style.display = '';
    } else {
      document.all[part_name].style.display = 'none';
    }
    return false;
  }else if (document.getElementById){
    if(document.getElementById(part_name).style.display == 'none'){
      document.getElementById(part_name).style.display = 'block';
    }else{
      document.getElementById(part_name).style.display = 'none';
    }
    return false;
  }
}

function CheckSignUp(poz){
  if (poz==1){
    if (document.forms.mainform.LName.value==''){
      alert('Please enter your Last Name');
      document.forms.mainform.LName.focus();
    }else if (document.forms.mainform.FName.value==''){
      alert('Please enter your First Name');
      document.forms.mainform.FName.focus();
    }else if (document.forms.mainform.TelNum.value==''){
      alert('Please enter your Phone Number');
      document.forms.mainform.TelNum.focus();
    }else if (!reEmail.test(document.forms.mainform.email.value)){
      alert("Invalid Email address!");
      document.forms.mainform.email.focus();
    }else{
      return true;
    }
    return false;
  }else if (poz==2){    
    var themessage='';
    if (document.forms.mainform.City.value=="") {
      themessage = themessage +  "\n - City";
    }
    if (document.forms.mainform.Country.value=="") {
      themessage = themessage +  "\n - Country";
    }
    if (document.forms.mainform.TelNum.value=="") {
      themessage = themessage +  "\n - Telephone Number";
      }

    if (document.forms.mainform.Pin.value=="") {
      themessage = themessage +  "\n - PIN";
    }
    if (document.forms.mainform.RefSource.selectedIndex < 1) {
      themessage = themessage + "\n  - How did you hear about us ";
    }
    if(themessage!='') {
      alert("You are required to complete the following fields: "+themessage);
      return false;
    }
    return true;
  }else{
    alert('Invalid poz');
  }
}

function CheckSignUp1(){
  var themessage='';
  var CheckA=new Array();
  
  CheckA[0]=new Array(2);
  CheckA[0][0]='Last Name';
  CheckA[0][1]='LName';

  CheckA[1]=new Array(2);
  CheckA[1][0]='First Name';
  CheckA[1][1]='FName';

  CheckA[2]=new Array(2);
  CheckA[2][0]='Mailing Address';
  CheckA[2][1]='MailAddr';

  CheckA[3]=new Array(2);
  CheckA[3][0]='City';
  CheckA[3][1]='City';

  CheckA[4]=new Array(2);
  CheckA[4][0]='Country';
  CheckA[4][1]='Country';

  CheckA[5]=new Array(2);
  CheckA[5][0]='E-mail Address';
  CheckA[5][1]='email';
  CheckA[5][2]='reEmail';

  CheckA[6]=new Array(2);
  CheckA[6][0]='Phone Number';
  CheckA[6][1]='TelNum';


  for (x=0;x<CheckA.length;x++){
    if (CheckA[x][2]){//ha van regexp
      eval('temp='+CheckA[x][2]+'.test(document.forms.mainform["'+CheckA[x][1]+'"].value);');
      if (temp==false) themessage=themessage + "\n  - "+CheckA[x][0];
    }else{
      eval('temp=document.forms.mainform["'+CheckA[x][1]+'"].value;');
      if (temp=='') themessage=themessage + "\n  - "+CheckA[x][0];
    }
  }

  if(themessage!='') {
    alert("You are required to complete the following fields: "+themessage);
    return false;
  }else{
    document.forms.mainform.SU_poz.value='2';
    document.forms.mainform.submit();
  }
}

function CheckSignUp2(){
  var themessage='';
  if (document.forms.mainform.ServiceType1.selectedIndex==0){
    themessage=themessage+"\n - The Service Type";
  }
  
  if (document.forms.mainform.CallbNumber1.value==''){
    themessage=themessage+"\n - Callback Number 1";
  }
  
  if (document.forms.mainform.MUsage1.selectedIndex==0){
    themessage=themessage+"\n - Monthly Usage";
  }
  
  
  if (document.forms.mainform.Pin.value.length<4){
    themessage=themessage+"\n - Pass Number";
  }
  
  if(themessage!='') {
    alert("You are required to complete the following fields: "+themessage);
    return false;
  }else{
    document.forms.mainform.SU_poz.value='3';
    document.forms.mainform.submit();
  }

}

function CountryChange(nr) {
  var Mem_User;
  eval('var CCode = document.forms.mainform["CountryCode'+nr+'"].value;');

  var VMem_User = String(CCode);
  if (VMem_User != ""){
    var TheString = VMem_User.substring(1,0);
    if (TheString == "1"){ 
      eval('document.forms.mainform["CallbNumber'+nr+'"].value="'+ CCode + '-";');
      return true;
    }else{ 
      eval('document.forms.mainform["CallbNumber'+nr+'"].value="011-'+ CCode + '-";');
      return true;
    }
    return true;
  }
}

function check_search(){
  if (document.forms.mainform.Search_keyword.value==''){
    alert('Please enter minimum 3 characters !');
    document.forms.mainform.Search_keyword.focus();
  }else{
    CPA('SearchPage');
  }
}

function openSignUpMoreInfo(){
  X=400;
  Y=250;
  windowprops="top="+(parseInt(screen.height)-parseInt(Y))/2+",left="+(parseInt(screen.width)-parseInt(X))/2+",status=no,scrollbars=no,directories=no,location=no,toolbar=no,resizable=no,menubar=no,width="+X+",height="+Y;
  window.open("includes/SignUpMoreInfo.html","Picture",windowprops);
}

//****************************************************************************************************************
function BrowserDetectLite() {
   var ua = navigator.userAgent.toLowerCase();

   // browser name
   this.isGecko     = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
   this.isMozilla   = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
   this.isNS        = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
   this.isIE        = ( (ua.indexOf('msie') != -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) );
   this.isSafari    = (ua.indexOf('safari') != - 1);
   this.isOpera     = (ua.indexOf('opera') != -1);
   this.isKonqueror = (ua.indexOf('konqueror') != -1 && !this.isSafari);
   this.isIcab      = (ua.indexOf('icab') != -1);
   this.isAol       = (ua.indexOf('aol') != -1);

   // spoofing and compatible browsers
   this.isIECompatible = ( (ua.indexOf('msie') != -1) && !this.isIE);
   this.isNSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.isNS && !this.isMozilla);

   // browser version
   this.versionMinor = parseFloat(navigator.appVersion);

   // correct version number
   if (this.isNS && this.isGecko) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
   }
   else if (this.isIE && this.versionMinor >= 4) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
   }
   else if (this.isMozilla) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.isSafari) {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
   }
   else if (this.isOpera) {
      if (ua.indexOf('opera/') != -1) {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera/') + 6 ) );
      }
      else {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera ') + 6 ) );
      }
   }
   else if (this.isKonqueror) {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.isIcab) {
      if (ua.indexOf('icab/') != -1) {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab/') + 6 ) );
      }
      else {
         this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab ') + 6 ) );
      }
   }

   this.versionMajor = parseInt(this.versionMinor);
   this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );

   // dom support
   this.isDOM1 = (document.getElementById);
   this.isDOM2Event = (document.addEventListener && document.removeEventListener);

   // css compatibility mode
   this.mode = document.compatMode ? document.compatMode : 'BackCompat';

   // platform
   this.isWin   = (ua.indexOf('win') != -1);
   this.isWin32 = (this.isWin && ( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1) );
   this.isMac   = (ua.indexOf('mac') != -1);
   this.isUnix  = (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1)
   this.isLinux = (ua.indexOf('linux') != -1);

   // specific browser shortcuts
   this.isNS4x = (this.isNS && this.versionMajor == 4);
   this.isNS40x = (this.isNS4x && this.versionMinor < 4.5);
   this.isNS47x = (this.isNS4x && this.versionMinor >= 4.7);
   this.isNS4up = (this.isNS && this.versionMinor >= 4);
   this.isNS6x = (this.isNS && this.versionMajor == 6);
   this.isNS6up = (this.isNS && this.versionMajor >= 6);
   this.isNS7x = (this.isNS && this.versionMajor == 7);
   this.isNS7up = (this.isNS && this.versionMajor >= 7);

   this.isIE4x = (this.isIE && this.versionMajor == 4);
   this.isIE4up = (this.isIE && this.versionMajor >= 4);
   this.isIE5x = (this.isIE && this.versionMajor == 5);
   this.isIE55 = (this.isIE && this.versionMinor == 5.5);
   this.isIE5up = (this.isIE && this.versionMajor >= 5);
   this.isIE6x = (this.isIE && this.versionMajor == 6);
   this.isIE6up = (this.isIE && this.versionMajor >= 6);

   this.isIE4xMac = (this.isIE4x && this.isMac);
}

function validatedCC(string) {
    for (var i=0, output='', valid="0123456789"; i<string.length; i++)
       if (valid.indexOf(string.charAt(i)) != -1)
          output += string.charAt(i)
    return output;
}
