function feedbackphoto(){
	var productid = document.getElementById("productid0").value;
	var dummy1 = document.getElementById("dummy1");
	var dummy2 = document.getElementById("dummy2");
	var photo1 = document.getElementById("photo1");
	var photo2 = document.getElementById("photo2");
	var photo3 = document.getElementById("photo3");

	var flag = false;
	if(!dummy1.checked && !dummy2.checked){
		flag = false;
	}else{
		flag = true;
	}

	if(!photo1.checked && !photo2.checked && !photo3.checked && !flag){
		flag = false;
	}else{
		flag = true;
	}
	if(!flag){
		alert("Please select one in questions!");
		return;
	}

	var dummy;
	var photo;
	if(dummy1.checked){
		dummy='1';
	}else if(dummy2.checked){
		dummy = '0';
	}else{
		dummy = '';
	}
	if(photo1.checked){
		photo = '2';
	}else if(photo2.checked){
		photo = '1';
	}else if(photo3.checked){
		photo = '0';
	}else{
		photo = '';
	}

	var url = 'buyerfeedback.do';
	var pars = 'pid='+productid+'&image='+photo+'&dummy='+dummy;
	document.getElementById("photo").style.visibility = "hidden";
	var myAjax = new Ajax.Request(url,{method:'post',parameters:pars,onComplete:feedbackresult});
}

function feedbackresult(req)
{
	var result = req.responseText;
	if(result=='right'){
		alert("Thank you! your opinion has been submitted!");
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	featurestemp = "toolbar=no,menubar=no,scrollbars=yes,resizable=yes, location=no,status=yes";
	window.open(theURL,winName,featurestemp);
}

function changeOrderSize(currentsize)
{
	var sSizeID;
	var sTempArr;
	var sOrderSize = null;

	sTempArr = currentsize.split(",");
	if( sTempArr.length > 1 )
	{
		sSizeID = sTempArr[1];
	}
	sOrderSize = document.productdisplayForm.elements["txt_" + sSizeID].value;
	document.productdisplayForm.quantity.value = sOrderSize;
	setcontrolvalue( 1,'currentordersize',getcontrolvalue(1,'quantity'));
}

function JudgeNum()
{
	var FormOrderSize;
	var OldOrderSize;
	FormOrderSize = getcontrolvalue(1,'quantity');
	OldOrderSize  = getcontrolvalue(1,'currentordersize');

	if (FormOrderSize < OldOrderSize)
	{
		alert("Sorry, your order does not meet the minimum quantity for " + OldOrderSize + ", please try again!");
		return false;
	}
	else
	{
		setformsubmit( 1 );
		return true;
	}
}

function ChangeImg(imgName)
{
	var sSmallimg;
	var sLargeimg;
	var  w,h;
	document.productdisplayForm.selectedpic.value = imgName;
	if (document.images)
	{
		sSmallimg = document[imgName].src;
	    sLargeimg = "http://image.dhgate.com/" + document.productdisplayForm.elements[imgName + "Large"].value;
	    //alert(sSmallimg);
	    //alert(sLargeimg);
	    document["Limg"].src = sLargeimg;
	    document.productdisplayForm.selectedpicurl.value = sLargeimg;
        //alert(productdisplayForm.selectedpicurl.value);//picurl
	    // onload="javascript:setImg(sLargeimg,Limg,200,200);"
	    if (typeof(document["Limg"]) == "object")
 		{
			w = document["Limg"].width;
			h = document["Limg"].height;
		 	if(w > h)
		 	{
		 		//document["Limg"].height = (200/w)*h;
		 		document["Limg"].width = 200;
		 	}
		 	else
		 	{
		 		document["Limg"].width = (200/h)*w;
		 		//document["Limg"].height = 200;
		 	}
		 }
	}
}

var imgObj;
function checkImg(theURL,winName)
{
   	var screenheight=screen.height;
   	var screenwidth=screen.width;
  	if (typeof(imgObj) == "object")
  	{
    	if ((imgObj.width != 0) && (imgObj.height != 0))
    	{
	   		if ((imgObj.width >= screenwidth) && (imgObj.height >= screenheight))
      		{
				OpenFullSizeWindow(theURL,winName,",width=800,height=600,scrollbars=yes");
	  		}
	  		else
	  		{
      			if ((imgObj.height > screenheight))
      			{
	      			OpenFullSizeWindow(theURL,winName,",width=" + (imgObj.width+20) + ",height=" + (screenheight-30) + ",scrollbars=yes");
      			}
      			else if (imgObj.width > screenwidth)
      			{
      				OpenFullSizeWindow(theURL,winName,",width=" + screenwidth + ",height=" + (imgObj.height+30) + ",scrollbars=yes");
      			}
        		else
        		{
      	 			OpenFullSizeWindow(theURL,winName, ",width=" + (imgObj.width+20) + ",height=" + (imgObj.height+30));
        		}
     		}
    	}
    	else
    	{
      		setTimeout("checkImg('" + theURL + "','" + winName + "')", 100);
     	}
  	}
}

function OpenFullSizeWindow(theURL,winName,features) {
	var aNewWin, sBaseCmd;
  	sBaseCmd = "toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,";
  	if (features == null || features == ""){
    	imgObj = new Image();
    	imgObj.src = theURL;
    	checkImg(theURL, winName)
  	}
  	else{
    	aNewWin = window.open(theURL,winName, sBaseCmd + features);
    	aNewWin.focus();
  	}
}

function Resize(imgObj)
{
	if (typeof(imgObj) == "object")
	{
		if(imgObj.width > imgObj.height)
		{
			imgObj.height = (imgObj.width/200)*imgObj.height;
			imgObj.width = 200;
		}
		else
		{
			imgObj.width = (imgObj.height/200)*imgObj.width;
			imgObj.height = 200;
		}
	}
}

function checkImg1(theURL,img,width,height)
{
	if ((img.width != 0) && (img.height != 0))
    {
    	setImg(theURL,img,width,height);
    }
    else
    {
    	setTimeout("checkImg1('" + theURL + "','" + img + "','" + width + "','" + height + "')", 200);
    }
}
function setImg(theURL,img,width,height)
{
	if ((img.width == 0) && (img.height == 0))
	{
		imgObj = new Image();
	    imgObj.src = theURL;
	    checkImg1(theURL,img,width,height)
   }
   else
   {
		var scale_w=img.width/width; 
		var scale_h=img.height/height;
		var scale=scale_w>scale_h?scale_w:scale_h;
	}
}
function judge()
{
	if(document.forms[1].elements["size"].value == "0")
	{
		alert("Please Select Size!");
		return false;
	}
	return true;
}

function show()
{
	var w,h,w0,h0;
	var k;
	var con;
	w=document.forms[1].elements["Limg"].width;
	h=document.forms[1].elements["Limg"].height;
	k=w/h;

	if(w > h)
  	{
  		h0 = (200/w)*h;
  		w0 = 200;

  	}
  	else
  	{
  		w0 = (200/h)*w;
  		h0 = 200;
  	}
	return w0;
}
