﻿
function handlechar(str)
{
    var arrchar = new Array();
    arrchar[0]=new Array("<","|?1?|");
    arrchar[1]=new Array(">","|?2?|");
    arrchar[2]=new Array('"','|?3?|');
    arrchar[3]=new Array("&","|?4?|");
    for(s=0;s<str.length;s++)
    {
        for(m=0;m<4;m++)
            str = str.replace(arrchar[m][0],arrchar[m][1]);
    }
    return str;
    
}
function showPay(iPayMent)
{
    for(j=0;j<3;j++)
        $("#DivClick"+j).css("display","none");
    $("input[name=PayMent][value="+iPayMent+"]").each(function(){$("#DivClick"+iPayMent).css("display","block");});
   parent.AdjustWindow(document.body.clientHeight);
}
function showdiv(objName,type)
{
    var _d=$("#"+objName);
    if(type==0)
        _d.css("display","none");
    else
        _d.css("display","block");
    parent.AdjustWindow(document.body.clientHeight);
    
}
function addstate(dropdownlist1,dropdownlist2)
{
    var obj1 = $("select[id="+dropdownlist1+"] option");
    var obj2 = $("select[id="+dropdownlist2+"]");
    var mPlayer=new Array();
    var StateID = "0";
    $("#"+dropdownlist2).empty();
    obj1.each(function(){if($(this).attr("selected") || $(this).attr("disabled")) 
    {      
        if($(this).attr("disabled")==false)
            $(this).attr("disabled",true);
        
        if($(this).attr("disabled")|| $(this).attr("selected")){
        mPlayer=$(this).val().split("|");
        if(mPlayer.length>1){ if(StateID!=mPlayer[0])
          {  var mlength=StateArray.length;
             for (var i=0; i<mlength; i++){ 
             if(mPlayer[0]==StateArray[i][1])
             {
               StateID=StateArray[i][1];
               $("<option  value='"+ StateArray[i][1] +"|0" + "'>"+ StateArray[i][2] +"</option>").appendTo(obj2); 
               break; }}  
          }}
        if(mPlayer.length>1) { if(StateID==mPlayer[0] && mPlayer[1]!="0"){
                $("<option value='"+$(this).val()+"'>"+$(this).text()+"</option>").appendTo(obj2);}}}
    } });
}

function Removestate(dropdownlist1,dropdownlist2)
{
    var obj1 = $("select[id="+dropdownlist1+"] option");
    var obj2 = $("select[id="+dropdownlist2+"] option");
    var mPlayer=new Array();
    var StateID = "0";
    
    obj2.each(function(){if($(this).attr("selected")) {
    StateID = $(this).val();
    $(this).remove();//1$(this).attr("disabled") ||
        obj1.each(function(){if(StateID==$(this).val()) $(this).attr("disabled",false);}); 
   }});
}
//+number
function checknumber(theFloat){

    var goalNum = theFloat.toString();
    var len=goalNum.length;
    var dotNum=0;
    if(len==0)
        return false;
    if(len==goalNum.indexOf('.')+1)
        return false;
    for(var i=0;i<len;i++){
        oneNum=goalNum.substring(i,i+1);
        if (oneNum==".")
            dotNum++;
        if ( ((oneNum<"0" || oneNum>"9") && oneNum!=".") || dotNum>1)
          return false;
    }
    if (len>1 && goalNum.substring(0,1)=="0"){
        if (goalNum.substring(1,2)!=".")
            return false;
    }
    return true;
}
function checkurl(value)
{
      value = value.toLowerCase();
      if(value.indexOf("http://",0)==-1)
        value = "http://"+value;
    　var pattern =/(\w+):\/\/([^\/:]+)(:\d*)?([^#]*)/; 
　　　var flag = pattern.exec(value); 
　　　if(flag)  
　　　　　return true; 
　　  else 
　　　　　return false; 
}

String.prototype.trim = function () {
				return this.replace(/^\s*/, "").replace(/\s*$/, "");
			}
function handlechar(str)
{
    var arrchar = new Array();
    arrchar[0]=new Array("<","|?1?|");
    arrchar[1]=new Array(">","|?2?|");
    arrchar[2]=new Array('"','|?3?|');
    arrchar[3]=new Array("&","|?4?|");
    for(s=0;s<str.length;s++)
    {
        for(m=0;m<4;m++)
            str = str.replace(arrchar[m][0],arrchar[m][1]);
    }
    return str;
    
}

var msg = new Array();
msg[0] = new Array("inptHeadline","Please enter a title!"," The title is empty.");
msg[1] = new Array("inpdescurl","Please enter a your web site url!"," The describe url is empty.","The description url is invalid.");
msg[2] = new Array("inptWebSite", "Please enter your web site url!", " The web site url is empty.", " The web site url is invalid.");
function adInit(objName)
{
    var m=0;
    for(j=0;j<msg.length;j++)
    {
        if(objName==msg[j][0])
        {
            m=j;
            break;
        }
    }
    $("#td_"+objName).attr("class","ad_select_tr");
    var pDiv = $("#"+objName+"_error");
    pDiv.attr("class","reg_tr_info");
    pDiv.attr("innerHTML",msg[j][1]);
    parent.AdjustWindow(document.body.clientHeight);
}

function checkinfo(objName)
{
    var pName = $("#"+objName);
    var pDiv = $("#"+objName+"_error");
    var pTd = $("#td_"+objName);
    var value = pName.attr("value");
    var index = 0;
    for(j=0;j<msg.length;j++)
    {
        if(objName==msg[j][0])
        {
            index=j;
            break;
        }
    }
    if(/^\s*$/.test(value))
    {
        pTd.attr("class","ad_select_err_tr");
        pDiv.attr("class","reg_tr_info_error");
        pDiv.attr("innerHTML",msg[index][2]);
    }
    else
    {
      if(objName=="inptWebSite" )
      {
        
        if(!checkurl(value))
        {
          pTd.attr("class","ad_select_err_tr");
          pDiv.attr("class","reg_tr_info_error");
          pDiv.attr("innerHTML",msg[index][3]);
        }
        else
        {
          pTd.attr("class","");
          pDiv.attr("class","");
          pDiv.attr("innerHTML","");
        }
      }
      else
      {
         pTd.attr("class","");
         pDiv.attr("class","");
         pDiv.attr("innerHTML","");
      }
       
    }
    parent.AdjustWindow(document.body.clientHeight);
}

///////////////////////////////setbudget js start ///////////////////
var msgb = new Array();
msgb[0] = new Array("inpcpc","The Max CPC must be number.","Please input your Max CPC!");
msgb[1] = new Array("inpbudget","The Daily Budget must be number.","Please input your Daily Budget!");
msgb[2] = new Array("inpcmp","The Max CMP must be number.","Please input your Max CMP!");
msgb[3] = new Array("inpmbudget","The Daily Budget must be number.","Please input your Daily Budget!");
function budInit(objName)
{
    var m=0;
    for(j=0;j<msgb.length;j++)
    {
        if(objName==msgb[j][0])
        {
            m=j;break;
        }
    }
    
    $("#td_"+objName).attr("class","ad_select_tr");
    var pDiv = $("#"+objName+"_error");
    pDiv.attr("class","reg_tr_info");
    pDiv.empty();
    pDiv.append(msgb[j][1]);
    parent.AdjustWindow(document.body.clientHeight);
}

function checkbudget(objName)
{
    var pName = $("#"+objName);
    var pDiv = $("#"+objName+"_error");
    var pTd = $("#td_"+objName);
    var value = pName.val();
    pDiv.attr("class","");
    pDiv.empty();
    pTd.attr("class","");
    var index = 0;
    for(j=0;j<msgb.length;j++)
        if(msgb[j][0]==objName)
            index = j;
            
    if(pName.val().trim().length>0)
    {
          
        if(checknumber(pName.val()))
            pName.attr("check","1");
        else
        {
            pTd.attr("class","ad_select_err_tr");
            pDiv.attr("class","reg_tr_info_error");
            pDiv.append(msgb[index][1]);
            pName.attr("check","0");
        }
    }
    else
        pName.attr("check","1"); 
            
    parent.AdjustWindow(document.body.clientHeight);
}
var submsg=new  Array();
submsg[0]="Opps, something is wrong.";
submsg[1]="Only Advertisers can create ad.";
submsg[2]="System error.";
submsg[3]="The ad Headline can not be empty.";
submsg[4]="The ad destination URL can not be empty.";
submsg[5] = "The ad destination URL is wrong.";
submsg[6]="The Max CPC must be a number.";
submsg[7]="The Daily Budget must be a number.";
submsg[8]="The Max CMP must be a number.";
submsg[9]="The Daily Budget must be a number.";
submsg[10]="You must enter keywords.";
submsg[11]="The ad website cann not be empty.";
submsg[12] = "The website url is invalid.";
